<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
        $paylist = $createlist = [];
        for ($i = 0; $i < 7; $i++)
        {
            $day = date("Y-m-d", $seventtime + ($i * 86400));
            $createlist[$day] = mt_rand(20, 200);
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
        }
        $hooks = config('addons.hooks');
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
        Config::parse($addonComposerCfg, "json", "composer");
        $config = Config::get("composer");
        $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');
        $this->view->assign([
            'totaluser'        => model('User')->count(),
            'totalviews'       => model('Mineral')->sum('today'),
            'totalorder'       => model('Trade')->count(),
            'totalorderamount' => model('Mineral')->sum('today')*0.125,
            'todayuserlogin'   => 321,
            'todayusersignup'  => 430,
            'todayorder'       => 2324,
            'unsettleorder'    => 132,
            'sevendnu'         => '80%',
            'sevendau'         => '32%',
            'paylist'          => $paylist,
            'createlist'       => $createlist,
            'addonversion'       => $addonVersion,
            'uploadmode'       => $uploadmode,
            'tradesellfto'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','FAE')->where('action','sell')->sum('surplusnum'),
            'tradebuyfto'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','FAE')->where('action','buy')->sum('surplusnum'),
            'tradesellftoall'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','FAE')->where('action','sell')->sum('num'),
            'tradebuyftoall'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','FAE')->where('action','buy')->sum('num'),
            'tradftoorderall'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','FAE')->count(),

            'tradesellcny'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','USDT')->where('action','sell')->sum('surplusnum'),
            'tradebuycny'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','USDT')->where('action','buy')->sum('surplusnum'),
            'tradesellcnyall'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','USDT')->where('action','sell')->sum('num'),
            'tradebuycnyall'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','USDT')->where('action','buy')->sum('num'),
            'tradcnyorderall'      =>  model('Trade')->where('symbol','USD')->where('tosymbol','USDT')->count(),

            'takeicoftotoday'      => model('Takeico')->where('icotype','FAE')->where('createtime','> time',date('Y-m-d'))->sum('num'),
            'takeicoftoall'      => model('Takeico')->where('icotype','FAE')->sum('num'),
            'takeicoftotodayun'      => model('Takeico')->where('icotype','FAE')->where('status','waitting')->count(),
            'takeicoethtoday'      => model('Takeico')->where('icotype','ETH')->where('createtime','> time',date('Y-m-d'))->sum('num'),
            'takeicoethall'      => model('Takeico')->where('icotype','ETH')->sum('num'),
            'takeicoethtodayun'      => model('Takeico')->where('icotype','ETH')->where('status','waitting')->count(),

            'runningmineral'       => model('Mineral')->where('status','running')->sum('num'),
            'mineralsum'       => model('Mineral')->sum('num'),
            'mineraltotal'       => model('Mineral')->sum('total'),
            'mineraltoday'       => model('Mineral')->sum('today'),
            'disputenum'        =>  model('Trade')->where('status','dispute')->count(),
            'disputetotalnum'        =>  model('Trade')->where('status','in',['disput','solve'])->count(),


        ]);

        return $this->view->fetch();
    }

}
